﻿using AutoMapper.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using taigu.WeChat;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace taigu
{
    /*奖项表相关的接口不先不管，目前可以暂放*/
    public class AwardsService : ApplicationService, IAwardsService
    {
        private readonly IRepository<Awards, Guid> _todoItemRepository;
        public AwardsService(IRepository<Awards, Guid> todoItemRepository)
        {
            _todoItemRepository = todoItemRepository;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="awards"></param>
        /// <returns></returns>
        [HttpPost,Route("/wechat/AwardsAdd")]
        public async Task<ResData<string>> AwardsAdd(CreateUpdateAwardsDto awards)
        {
            try
            {
                awards.id = Guid.NewGuid();
                await _todoItemRepository.InsertAsync(ObjectMapper.Map<CreateUpdateAwardsDto, Awards>(awards));
                return new ResData<string>() { Status = ResStatus.成功, Msg = "sucess", Info = "" };
            }
            catch
            {
                return new ResData<string>() { Status = ResStatus.failed, Msg = "sucess", Info = "" };
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("/wechat/AwardsDelete")]
        public async Task<ResData<string>> AwardsDelete(Guid id)
        {        
            try
            {
                await _todoItemRepository.DeleteAsync(id);
                return new ResData<string>() { Status = ResStatus.成功, Msg = "sucess", Info = "" };
            }
            catch
            {
                return new ResData<string>() { Status = ResStatus.failed, Msg = "fail", Info = "" };
            }
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost, Route("/wechat/AwardsFill")]
        public async Task<AwardsDto> AwardsFill(Guid id)
        {
            var item = await _todoItemRepository.FindAsync(id);

            return ObjectMapper.Map<Awards, AwardsDto>(item);
        }

        /// <summary>
        /// 显示方法
        /// </summary>
        /// <returns></returns>
        [HttpPost,Route("/wechat/AwardsShow")]
        [AllowAnonymous]
        public async Task<List<AwardsDto>> AwardsShow()
        {
            var items = await _todoItemRepository.GetListAsync();

            return ObjectMapper.Map<List<Awards>, List<AwardsDto>>(items);

        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="awards"></param>
        /// <returns></returns>
        [HttpPost, Route("/wechat/AwardsUpdate")]
        public async Task<ResData<string>> AwardsUpdate(CreateUpdateAwardsDto awards)
        {
            await _todoItemRepository.UpdateAsync(ObjectMapper.Map<CreateUpdateAwardsDto, Awards>(awards));

            return new ResData<string>() { Status = ResStatus.成功, Msg = "sucess", Info = "" };
        }
    }
}
